package com.cloudlibrary.mapper;

import com.cloudlibrary.domain.Record;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

/**
* @author 30590
* @description 针对表【record】的数据库操作Mapper
* @createDate 2024-12-18 18:15:17
* @Entity com.cloudlibrary.domain.Record
*/
public interface RecordMapper{

    @Insert("insert into record( record_id,record_bookname,record_bookisbn,record_borrower," +
            "record_borrowtime,record_remandtime)" +
            "values(#{id},#{bookname},#{bookisbn},#{borrower},#{borrowtime},#{remandtime})")
    Integer addRecord(Record record);

    @Select({"<script>"+
            "select * from record"+
            " where 1=1"+
            "<if test=\"borrower !=null\"> " +
            "and borrower like concat('%','{borrower}','%') </if>" +
            "<if test=\"bookname !=null\">  " +
            "and bookname like concat('%','{bookname}','%') </if>" +
            "order by record_remandtime desc" +
            "</script>"})
    @Results(id = "recordMap",value = {
            @Result(id = true,column = "record_id",property = "id"),
            @Result(column = "record_bookname",property = "bookname"),
            @Result(column = "record_bookisbn",property = "bookisbn"),
            @Result(column = "record_borrower",property = "borrower"),
            @Result(column = "record_borrowtime",property = "borrowtime"),
            @Result(column = "record_remandtime",property = "remandtime")
    })
    Page<Record> searchRecords(Record record);
}




